package com.xinghou.platform.lucene.main.bean;

import com.xinghou.platform.model.main.SharedCard;
import com.xinghou.platform.util.StringUtils;
import org.apache.solr.client.solrj.beans.Field;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qingshengzheng on 16/4/26.
 */
public class SharedCardSolr {
    @Field
    public Integer status;
    @Field
    public Integer cardid;
    @Field
    public Integer userid;
    @Field
    public Integer storeid;
    @Field
    public String cardcontent;
    @Field
    public Integer praisecount;
    @Field
    public Integer browsecount;
    @Field
    public String sharetype;
    @Field
    public Long createtime;
    @Field
    public String citycode;
    @Field
    public Integer cityid;
    @Field
    public String storename;
    @Field
    public String position;
    @Field
    public List<Integer> usearea=new ArrayList<Integer>();
    @Field
    public Double minsale;
    @Field
    public String storeaddress;
    @Field
    public String transactiontype;
    @Field
    public Double	discount;


    @Field
    public String ad_code;
    @Field
    public String ad_code_province;
    @Field
    public String ad_code_region;
    @Field
    public String ad_code_city;



    public static SharedCardSolr fromSharedCard(SharedCard shareCard) {
        SharedCardSolr solr = new SharedCardSolr();
        solr.status = shareCard.getStatus()==null?null:Integer.parseInt(shareCard.getStatus().toString());
        solr.cardid = shareCard.getCardid();
        solr.userid = shareCard.getUserid();
        solr.storeid = shareCard.getStoreid();
        solr.storename=shareCard.getStorename();
        solr.storeaddress=shareCard.getStoreaddress();
        solr.transactiontype=shareCard.getTransactiontype();
        solr.cardcontent = shareCard.getContent();
        solr.praisecount = shareCard.getPraisecount();
        solr.sharetype=shareCard.getSharetype()==null?null:shareCard.getSharetype().toString();
        solr.browsecount = shareCard.getBrowsecount();
        if(shareCard.getLatitude()!=null&&shareCard.getLongitude()!=null)
        solr.position=shareCard.getLatitude()+","+shareCard.getLongitude();
        solr.minsale=shareCard.getMinsale();
        solr.discount=shareCard.getDiscount()==null?null:Double.parseDouble(shareCard.getDiscount());

        solr.ad_code=shareCard.getAd_code();
        solr.ad_code_province=shareCard.getAd_code_province();
        solr.ad_code_city=shareCard.getAd_code_city();
        solr.ad_code_region=shareCard.getAd_code_region();
        if(!StringUtils.isEmpty(shareCard.getUsearea()))
        {
            String[] temps=shareCard.getUsearea().split("-");
            for(int i=0;i<temps.length;i++)
            {
               solr.usearea.add(Integer.parseInt(temps[i]));
            }
        }
        return solr;
    }
    public SharedCard toSharedCard()
    {
        SharedCard sharedCard=new SharedCard();
        sharedCard.setStatus(status==null?null:Short.parseShort(status.toString()));
        sharedCard.setSharetype(sharetype==null?null:Byte.parseByte(sharetype));
        sharedCard.setCardid(cardid);
        sharedCard.setUserid(userid);
        sharedCard.setStoreid(storeid);
        sharedCard.setContent(cardcontent);
        sharedCard.setPraisecount(praisecount);
        sharedCard.setBrowsecount(browsecount);
        if(!StringUtils.isEmpty(position)) {
            sharedCard.setLatitude(Double.parseDouble(position.split(",")[0]));
            sharedCard.setLongitude(Double.parseDouble(position.split(",")[1]));
        }
        return sharedCard;
    }


}
